<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <table>
            <thead>
                <td>id</td>
                <td>name</td>
                <td>age</td>
                <td>birthday</td>
            </thead>
            <tr v-for="(student,index) in students">
                <td>{{index | handle}}</td>
                <td>{{student.name}}</td>
                <td>{{student.age}}</td>
                <td>{{student.birthday}}</td>
                <td><input type="submit" value="删除" @click="deleteStu(index)"></td>
            </tr>
        </table>
        <form action="#">
            用户名：<input type="text" placeholder="username" name="username">
            年 龄：<input type="text" placeholder="age" name="age">
            生 日：<input type="date" placeholder="birthday" name="birthday">
            <input type="submit" value="添加" @click.prevent="addStu">
        </form>
    </div>
    <script src="vuejs/vue.js"></script>
    <script type="text/javascript">
    function Student(name,age,birthday) {
        this.name = name;
        this.age = age;
        this.birthday = birthday;
    }
        let app = new Vue({
        data: {
            students: [
                {
                    name: '张三',
                    age: 18,
                    birthday: '2020-01-01'
                },
                {
                    name: '张三',
                    age: 18,
                    birthday: '2020-01-01'
                },
                {
                    name: '张三',
                    age: 18,
                    birthday: '2020-01-01'
                },
                {
                    name: '张三',
                    age: 18,
                    birthday: '2020-01-01'
                }
            ]
        },
        methods: {
            deleteStu(index) {
                this.students.splice(index,1);
            },
            addStu() {
                let form = document.forms[0];
                let stu = new Student(form['username'].value,form['age'].value,form['birthday'].value);
                this.students.push(stu);
            }
        },
        filters: {
            handle(value) {
                return '100' + new String(value + 1);
            }
        }
        }).$mount('#app');
    </script>
</body>
</html>